package com.qipay.api.qq.controller.v1;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qipay.baas.model.Cp;
import com.qipay.baas.model.Order;
import com.qipay.cp.CpService;
import com.qipay.order.config.OrderStateEnum;
import com.qipay.order.service.OrderService;
import com.qipay.pay.AlipayWapService;
import com.qipay.scalar.type.ApiStatusEnum;
import com.qipay.security.sign.service.SignService;
import com.qipay.sp.SpApiConfigService;
import com.qipay.sp.SpConfigService;
import com.qipay.utils.ResultUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/redirect/v1/qq")
public class QQRedirectController {

    protected final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    CpService cpService;

    @Autowired
    SignService signService;

    @Autowired
    AlipayWapService alipayWapService;

    @Autowired
    OrderService orderService;

    @Autowired
    SpConfigService spConfigService;

    @Autowired
    SpApiConfigService spApiConfigService;

    @Autowired
    ObjectMapper objectMapper;

    @Value("${api.response.sign.name}")
    private String sigKey;

    /**
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/otherwap", method = RequestMethod.GET, produces = {"application/xml;charset=UTF-8"})
    private void otherwap(
            HttpServletRequest request,
            @RequestParam("tradeNo") String tradeNo,
            HttpServletResponse response
    ) throws Exception {
        Assert.notNull(tradeNo, "请输入平台交易流水");
        Order order = orderService.getByTradeNo(tradeNo);
        if(order!=null&&order.getRemark()!=null){
            response.sendRedirect(order.getRemark());
        }
    }
}
